﻿<ui:DialogWindow x:Class="CrmCodeGenerator.VSPackage.Dialogs.Login"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:vs_shell="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.12.0"
        xmlns:ui="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.12.0"                 
        xmlns:control="clr-namespace:CrmCodeGenerator.Controls;assembly=CrmCodeGenerator.Controls"
        xmlns:converter="clr-namespace:CrmCodeGenerator.VSPackage.Dialogs.Converters"
        Title="CRM Code Generator Configuration" Width="470" SizeToContent="Height" Loaded="Window_Loaded" WindowStartupLocation="CenterOwner">

    <Window.Resources>
        <Style TargetType="Grid" >
            <!--<Setter Property="Background"  Value="{DynamicResource {x:Static vs_shell:EnvironmentColors.DialogBrushKey}}"/>-->
            <!--<Setter Property="Background"  Value="Blue"></Setter>-->
        </Style>
        <Style TargetType="Label">
            <!--<Setter Property="Foreground" Value="{DynamicResource {x:Static vs_shell:EnvironmentColors.DialogTextBrushKey}}"/>
            <Setter Property="FontFamily" Value="{DynamicResource VsFont.EnvironmentFontFamily}" />
            <Setter Property="FontSize" Value="{DynamicResource VsFont.EnvironmentFontSize}" />-->
            <Setter Property="Margin" Value="-4,0,0,-4" />
        </Style>
        <Style TargetType="TextBox">
            <!--<Setter Property="Foreground" Value="{DynamicResource {x:Static vs_shell:EnvironmentColors.ToolWindowTextBrushKey}}"/>
            <Setter Property="Background" Value="{DynamicResource {x:Static vs_shell:EnvironmentColors.ToolWindowBackgroundBrushKey}}"/>-->
            <!--<Setter Property="FontFamily" Value="{DynamicResource VsFont.EnvironmentFontFamily}" />
            <Setter Property="FontSize" Value="{DynamicResource VsFont.EnvironmentFontSize}" />-->
            <Setter Property="Margin" Value="0,0,0,0" />
            <Setter Property="Height" Value="20" />
        </Style>
        <Style TargetType="PasswordBox">
            <!--<Setter Property="Foreground" Value="{DynamicResource {x:Static vs_shell:EnvironmentColors.ToolWindowTextBrushKey}}"/>
            <Setter Property="Background" Value="{DynamicResource {x:Static vs_shell:EnvironmentColors.ToolWindowBackgroundBrushKey}}"/>-->
            <!--<Setter Property="FontFamily" Value="{DynamicResource VsFont.EnvironmentFontFamily}" />
            <Setter Property="FontSize" Value="{DynamicResource VsFont.EnvironmentFontSize}" />-->
            <Setter Property="Margin" Value="0,0,0,0" />
            <Setter Property="Height" Value="20" />
        </Style>
        <Style TargetType="CheckBox">
            <!--<Setter Property="Foreground" Value="{DynamicResource {x:Static vs_shell:EnvironmentColors.ToolWindowTextBrushKey}}"/>
            <Setter Property="Background" Value="{DynamicResource {x:Static vs_shell:EnvironmentColors.ToolWindowBackgroundBrushKey}}"/>-->
            <!--<Setter Property="Background"  Value="{DynamicResource {x:Static vs_shell:EnvironmentColors.DialogBrushKey}}"/>
            <Setter Property="Foreground" Value="{DynamicResource {x:Static vs_shell:EnvironmentColors.DialogTextBrushKey}}"/>
            <Setter Property="FontFamily" Value="{DynamicResource VsFont.EnvironmentFontFamily}" />
            <Setter Property="FontSize" Value="{DynamicResource VsFont.EnvironmentFontSize}" />-->
            <Setter Property="Margin" Value="0,0,15,0" />
            
        </Style>
        <Style TargetType="ComboBox">
            <!--<Setter Property="Foreground" Value="{DynamicResource {x:Static vs_shell:EnvironmentColors.ToolWindowTextBrushKey}}"/>
            <Setter Property="Background" Value="{DynamicResource {x:Static vs_shell:EnvironmentColors.ToolWindowBackgroundBrushKey}}"/>-->
            <!--<Setter Property="FontFamily" Value="{DynamicResource VsFont.EnvironmentFontFamily}" />
            <Setter Property="FontSize" Value="{DynamicResource VsFont.EnvironmentFontSize}" />-->
            <Setter Property="Margin" Value="0,0,0,0" />
        </Style>
        <!--<Style TargetType="TextBlock">
            <Setter Property="Background"  Value="{DynamicResource {x:Static vs_shell:EnvironmentColors.DialogBrushKey}}"/>
            <Setter Property="Foreground" Value="{DynamicResource {x:Static vs_shell:EnvironmentColors.DialogTextBrushKey}}"/>
            <Setter Property="FontFamily" Value="{DynamicResource VsFont.EnvironmentFontFamily}" />
            <Setter Property="FontSize" Value="{DynamicResource VsFont.EnvironmentFontSize}" />
        </Style>-->
        <!--<Style TargetType="Button">
            <Setter Property="FontFamily" Value="{DynamicResource VsFont.EnvironmentFontFamily}" />
            <Setter Property="FontSize" Value="{DynamicResource VsFont.EnvironmentFontSize}" />
            <Setter Property="Padding" Value="5" />-->
        <!--<Setter Property="Background" Value="{DynamicResource {x:Static vs_shell:EnvironmentColors.ToolWindowButtonInactiveBrushKey}}" />-->
        <!--<Style.Triggers>
                <Trigger Property="IsMouseOver" Value="true">
                    <Setter Property="BorderBrush" Value="{DynamicResource {x:Static vs_shell:EnvironmentColors.CommandBarBorderBrushKey}}" />
                    <Setter Property="Background" Value="{DynamicResource {x:Static vs_shell:EnvironmentColors.CommandBarMouseOverBackgroundGradientBrushKey}}" />-->
        <!--<Setter Property="TextElement.Foreground" Value="{DynamicResource {x:Static vs_shell:EnvironmentColors.CommandBarTextHoverBrushKey}}"/>-->
        <!--</Trigger>
            </Style.Triggers>
        </Style>-->
        <converter:BoolToVisibilityConverter x:Key="BoolToHiddenConverter" TrueValue="Visible" FalseValue="Collapsed"/>
    </Window.Resources>
    <Window.CommandBindings>
        <CommandBinding Command="Close" Executed="Cancel_Click" />
    </Window.CommandBindings>
    <Window.InputBindings>
        <KeyBinding Key="Escape" Command="Close" />
    </Window.InputBindings>

    <StackPanel x:Name="Inputs" Grid.Column="0" Grid.Row="0" Margin="5,10,5,10" >
        <Label>CRM Connection</Label>
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" Margin="0,10,0,5">
            <CheckBox IsChecked="{Binding UseSSL, Mode=TwoWay}" IsEnabled="{Binding CanUseSSL}" x:Name="UseSSL">Use SSL</CheckBox>
            <CheckBox IsChecked="{Binding UseIFD, Mode=TwoWay}"  IsEnabled="{Binding CanUseIfd}" x:Name="UseIFD">Use IFD</CheckBox>
            <CheckBox IsChecked="{Binding UseOnline, Mode=TwoWay}" x:Name="UseOnline">Use CRM Online</CheckBox>
            <CheckBox IsChecked="{Binding UseOffice365, Mode=TwoWay}" x:Name="UseOffice365">Use Office 365</CheckBox>
        </StackPanel>
        <Grid>
            <Grid.Resources>
                <Style TargetType="{x:Type TextBox}">
                    <Setter Property="Margin" Value="0,3,0,2" />
                    <Setter Property="Height" Value="20" />
                </Style>
                <Style TargetType="{x:Type ComboBox}">
                    <Setter Property="Margin" Value="0,3,0,2" />
                    <Setter Property="Height" Value="20" />
                </Style>
            </Grid.Resources>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <!---->
                <Label Grid.Column="0"  Grid.Row="0" Grid.RowSpan="2" VerticalAlignment="Top" >Server Name</Label>
                <TextBox  Grid.Column="1"  Grid.Row="0"  Text="{Binding ServerName, Mode=TwoWay}" Visibility="{Binding NeedServer, Converter={StaticResource BoolToHiddenConverter} }" ></TextBox>
            <ComboBox Margin="0,3,0,2" Grid.Column="1"  Grid.Row="0" 
        		IsTextSearchEnabled="True" 
        		Text="{Binding ServerName, Mode=TwoWay}"
                Visibility="{Binding NeedOnlineServer, Converter={StaticResource BoolToHiddenConverter} }"            
        		x:Name="OnlineServer">
                <!--ItemsSource="{Binding OnLineServers, Mode=TwoWay}"-->
            <ComboBoxItem IsSelected="True">crm.dynamics.com</ComboBoxItem>
            <ComboBoxItem >crm2.dynamics.com</ComboBoxItem>
            <ComboBoxItem >crm4.dynamics.com</ComboBoxItem>
            <ComboBoxItem >crm5.dynamics.com</ComboBoxItem>
            </ComboBox>
            <Label Grid.Column="0"  Grid.Row="1"  IsEnabled="{Binding NeedServerPort }">Server Port</Label>
            <TextBox Grid.Column="1"  Grid.Row="1" IsEnabled="{Binding NeedServerPort }" Text="{Binding ServerPort, Mode=TwoWay}"></TextBox>
            <Label Grid.Column="0"  Grid.Row="2" IsEnabled="{Binding NeedHomeRealm}" >Home Realm Url</Label>
            <TextBox Grid.Column="1"  Grid.Row="2" IsEnabled="{Binding NeedHomeRealm}" Text="{Binding HomeRealm, Mode=TwoWay}"  HorizontalAlignment="Stretch"></TextBox>
        </Grid>

        <StackPanel Margin="0,10,0,10">
            <CheckBox IsChecked="{Binding UseWindowsAuth, Mode=TwoWay}" IsEnabled="{Binding CanUseWindowsAuth}" x:Name="UseWindowAuth">Windows Authentication</CheckBox>

            <Label Content="Username" />
            <TextBox Text="{Binding Username, Mode=TwoWay}" x:Name="Username" IsEnabled="{Binding NeedCredentials}"  />
            <Label Content="Password"  />
            <!--<TextBox Text="{Binding Path=Password, Mode=TwoWay}" Name="Password"   />-->
            <PasswordBox x:Name="txtPassword" IsEnabled="{Binding NeedCredentials}"/>
            <Label Content="Domain" IsEnabled="{Binding NeedCredentials}" />
            <TextBox Text="{Binding Domain, Mode=TwoWay}" x:Name="Domain"  />
        </StackPanel>


        <!--<Label Content="Discorvy URL" />
        <TextBox  x:Name="DiscoryURL" Text="{Binding CrmSdkUrl, Mode=TwoWay}" IsEnabled="False" />-->
        <StackPanel>
            <Label Content="Organization"/>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <ComboBox Grid.Column="0"  
        		IsTextSearchEnabled="True" 
        		IsEditable="True" 
        		ItemsSource="{Binding OrgList, Mode=TwoWay}"
        		Text="{Binding CrmOrg, Mode=TwoWay}"
        		x:Name="Organization" />
                <!--ItemsSource="{Binding Items}" 
                          SelectedValuePath="Text"
                          Text="{Binding SelectedItemText, Mode=TwoWay}"-->
                <Button Grid.Column="1" x:Name="Logon"  HorizontalAlignment="Right" Content="Refresh" Click="RefreshOrgs"  CommandParameter="{Binding ElementName=txtPassword}"/>
            </Grid>
        </StackPanel>
        <StackPanel Margin="0,10,0,10">
            <Label Content="Include Entities" />
            <Grid Background="Transparent">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <control:MultiSelectComboBox Grid.Column="0" Width="auto" ItemsSource="{Binding EntityList, Mode=TwoWay}" SelectedItems="{Binding EntitiesSelected, Mode=TwoWay}" x:Name="Entities" ToolTip="{Binding Text, RelativeSource={RelativeSource Self}}"/>
                <Button Grid.Column="1" x:Name="EntitiesRefresh"  HorizontalAlignment="Right" Content="Refresh" Click="EntitiesRefresh_Click"  CommandParameter="{Binding ElementName=txtPassword}"/>
                <StackPanel  Grid.Column="0" Grid.Row="1"  Orientation="Horizontal">
                <CheckBox IsChecked="{Binding IncludeNonStandard, Mode=TwoWay}" x:Name="IncludeNonStandard" Checked="IncludeNonStandardEntities_Click" Unchecked="IncludeNonStandardEntities_Click" ToolTipService.ShowDuration="30000">
                    <CheckBox.ToolTip>
                        <ToolTip>
                            <StackPanel>
                                <TextBlock FontWeight="Bold"><Run Text="NON-Standard Entities"/></TextBlock>
                                <TextBlock><Run Text="The CrmSvcUtil.exe program excludes a lot of NON-Standard entities."/><LineBreak /><Run Text="Some are clearly not meant for end user development (eg replicationbacklog, multientitysearchentities, integrationstatus)."/><LineBreak /><Run Text="Some may be useful, but would have to be considered &quot;Microsoft Unsupported&quot; (eg attachment, notification, subscription)."/></TextBlock>
                            </StackPanel>
                        </ToolTip>
                    </CheckBox.ToolTip>
                    <!--  Background="{DynamicResource {x:Static vs_shell:EnvironmentColors.DialogBrushKey}}" -->
                    <TextBlock Background="Transparent"><Run Text="Include NON-Standard Entities"/></TextBlock>
                </CheckBox>
                    <CheckBox IsChecked="{Binding IncludeUnpublished, Mode=TwoWay}" ToolTipService.ShowDuration="30000">
                        <CheckBox.ToolTip>
                            <ToolTip>
                                <StackPanel>
                                    <TextBlock FontWeight="Bold"><Run Text="Unpublished changes"/></TextBlock>
                                    <TextBlock><Run Text="Leave unchecked to ignore the changes that haven't yet been published."/><LineBreak /><Run Text="Some are clearly not meant for end user development (eg replicationbacklog, multientitysearchentities, integrationstatus)."/><LineBreak /><Run Text="Some may be useful, but would have to be considered &quot;Microsoft Unsupported&quot; (eg attachment, notification, subscription)."/></TextBlock>
                                </StackPanel>
                            </ToolTip>
                        </CheckBox.ToolTip>
                        <TextBlock Background="Transparent"><Run Text="Unpublished changes"/></TextBlock>
                    </CheckBox>
                </StackPanel>
            </Grid>
        </StackPanel>

        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
            <Button Click="Logon_Click" CommandParameter="{Binding ElementName=txtPassword}" Content="Generate Code" />
        </StackPanel>
    </StackPanel>
</ui:DialogWindow>
